﻿using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;

namespace org.se.fs.view.Profile
{
    public partial class FrmClientInstitutionRecords : Form
    {
        private DataTable _data;

        public FrmClientInstitutionRecords()
        {
            InitializeComponent();
            datagridview.AutoGenerateColumns = false;
        }

        public static void FormShow(DataTable data)
        {
            using (var frmForm = new FrmClientInstitutionRecords())
            {
                frmForm._data = data;
                frmForm.ShowDialog();
            }
        }

        private void BtnCloseClick(object sender, EventArgs e)
        {
            Close();
        }

        private void FrmClientInstitutionRecordsLoad(object sender, EventArgs e)
        {
            var data =
                (_data.AsEnumerable().Select(
                    a =>
                    new
                        {
                            BRANCH = string.Format("{0}-{1}", a.Field<string>("branch_name"), a.Field<string>("branch_code")),
                            INSTITUTION = string.Format("{0}-{1}", a.Field<string>("institution_name"),
                                      a.Field<string>("institution_code")),
                            DATE = string.Format("{0} {1}", a.Field<DateTime>("created_date").ToShortDateString(),
                                      a.Field<DateTime>("created_date").ToShortTimeString()),
                            ENCODER = a.Field<string>("user_name")
                        })).ToArray();
            datagridview.DataSource = data;
        }
    }
}